
import 'dart:math' as Math;
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:dutask/data/LUMAHomeEnvironment.dart';
import 'package:dutask/models/LUMATasks.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class LUMAExtensionsOptimistic extends Notifier<List<ListModel>> {
  List<ListModel> _parseListenerCurrentAfterDrawer() {
    return defaultLists;
  }

  @override
  build() {
    return _parseListenerCurrentAfterDrawer();
  }

  late List<ListModel> previousState;

  void createList(ListModel list) {
    previousState = [...state];
    state = [...state, list];
  }

  void updateList(String listId, ListModel updatedList) {
    previousState = [...state];
    final localPreviousState = [...state];
    final listToReplaceIndex = state.indexWhere((list) => list.id == listId);
    localPreviousState[listToReplaceIndex] = updatedList;
    state = [...localPreviousState];
  }

  void deleteList(String listId) {
    previousState = [...state];
    state = [...state.where((list) => list.id != listId).toList()];
  }

  void undo() {
    final localPreviousState = [...state];
    state = [...previousState];
    previousState = [...localPreviousState];
  }
}

final listsProvider = NotifierProvider<LUMAExtensionsOptimistic, List<ListModel>>(
  LUMAExtensionsOptimistic.new,
);
